<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="isEdit ? '修改考评等级' : '新增考评等级'"
    width="800px"
    :footer="null"
    :visible.sync="visible"
  >
    <el-form :model="form" ref="form" label-width="180px" :rules="rules">
      <el-form-item label="考评等级名称" prop="moralityLevelName">
        <el-input v-model="form.moralityLevelName" placeholder="请输入考评等级名称" />
      </el-form-item>
      <!-- <el-form-item label="最大分值" prop="maxScore">
        <el-input v-model.number="form.maxScore" placeholder="请输入最大分值" />
      </el-form-item>
      <el-form-item label="最小分值" prop="minScore">
        <el-input v-model.number="form.minScore" placeholder="请输入最小分值" />
      </el-form-item>
      <el-form-item label="科室考评环节人数比上限" prop="deptPecent">
        <el-input v-model.number="form.deptPecent" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="党支部考评环节人数比上限" prop="branchPecent">
        <el-input v-model.number="form.branchPecent" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="考评委员会环节人数比上限" prop="committeePecent">
        <el-input v-model.number="form.committeePecent" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="是否限制人数" prop="peopleLimit">
        <el-radio-group v-model="form.peopleLimit">
          <el-radio :label="0">否</el-radio>
          <el-radio :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>-->
    </el-form>
    <div slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handleSure">{{ isEdit ? '修改' : '新增' }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { levelCreate, levelUpdate } from '@/api/morality'
import { openNotification } from '@/utils/util'

export default {
  data() {
    return {
      isEdit: false,
      visible: false,
      form: {
        moralityLevelName: null,
        maxScore: null,
        minScore: null,
        deptPecent: null,
        committeePecent: null,
        branchPecent: null,
        peopleLimit: null
      },
      rules: {
        moralityLevelName: [{ required: true, message: '请输入评语模板名称', trigger: 'blur' }],
        deptPecent: [{ type: 'number', message: '请输入数字', trigger: 'blur' }],
        committeePecent: [{ type: 'number', message: '请输入数字', trigger: 'blur' }],
        branchPecent: [{ type: 'number', message: '请输入数字', trigger: 'blur' }],
        maxScore: [{ type: 'number', message: '请输入数字', trigger: 'blur' }],
        minScore: [{ type: 'number', message: '请输入数字', trigger: 'blur' }],
        peopleLimit: [{ required: true, message: '请选择是否限制人数', trigger: 'blur' }]
      }
    }
  },
  methods: {
    edit(bool, row) {
      this.isEdit = bool
      this.form = Object.assign({}, row)
      this.visible = true
    },
    handleSure() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          let res = '',
            mes = ''
          if (this.isEdit) {
            mes = '修改操作成功'
            res = await levelUpdate(this.form)
          } else {
            mes = '新增操作成功'
            res = await levelCreate(this.form)
          }
          if (res.state === '000000') {
            openNotification('success', mes)
            this.visible = false
            this.$emit('refresh')
          }
        }
      })
    }
  }
}
</script>
